//
//  PlatformType.m
//  reSearchDemo
//
//  Created by 科技 on 15/7/31.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "PlatformType.h"
#import "PersonalPlatform.h"
#import "LoginYunPlaVC.h"
@interface PlatformType ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray *SelectBtnArr;  /**< 存放btn的数组 */
    UIView *_headView;
}
@end

@implementation PlatformType

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIView * actionbar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 44)];
    self.navigationItem.titleView = actionbar;
    UILabel * lab=[[UILabel alloc]initWithFrame:CGRectMake(8, 0, 100, 40)];
    lab.text=@"云平台性质";
    lab.font=[UIFont systemFontOfSize:20];
    lab.textColor=[UIColor whiteColor];
    [actionbar addSubview:lab];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:_tableView];
    
    SelectBtnArr = [[NSMutableArray alloc] init];
    
    _headView = [self buildMainView];
}

-(UIView *)buildMainView {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
    CGSize size = [@"平台性质:" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}];
    UILabel *textlabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 40, size.width, 30)];
    textlabel.font = [UIFont systemFontOfSize:17];
    textlabel.text = @"平台性质:";
    [headView addSubview:textlabel];
    NSArray *titleArr = @[@"个人平台",@"企业平台",@"商协会",@"事业单位",@"公共服务"];
    for (int i = 0; i < 5; i++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(textlabel.frame) + 10, CGRectGetMinY(textlabel.frame) + 35*i, size.width, 30)];
        label.text = titleArr[i];
        
        UIButton *SelectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        SelectBtn.frame = CGRectMake(CGRectGetMaxX(label.frame) + 10, CGRectGetMinY(label.frame) + 5, 20, 20);
        SelectBtn.selected = NO;
        [SelectBtn setImage:[UIImage imageNamed:@"btn_radio_n@2x"] forState:UIControlStateNormal];
        [SelectBtn setImage:[UIImage imageNamed:@"btn_radio_s@2x"] forState:UIControlStateSelected];
        [SelectBtn addTarget:self action:@selector(SelectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 1) {
            SelectBtn.selected = YES;
        }
        
        [headView addSubview:label];
        [headView addSubview:SelectBtn];
        [SelectBtnArr addObject:SelectBtn];
    }
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(CGRectGetMinX(textlabel.frame), CGRectGetMaxY(textlabel.frame) + 5*30 + 20, CGRectGetWidth(self.view.frame) - 2*CGRectGetMinX(textlabel.frame), 40);
    [sureBtn setTitle:@"确定" forState:0];
    [sureBtn setTitleColor:[UIColor blackColor] forState:0];
    [sureBtn setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [sureBtn addTarget:self action:@selector(SureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:sureBtn];
    
    UIButton *skipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    skipBtn.frame = CGRectMake(CGRectGetMinX(sureBtn.frame), CGRectGetMaxY(sureBtn.frame) + 20, CGRectGetWidth(sureBtn.frame), CGRectGetHeight(sureBtn.frame));
    [skipBtn setTitle:@"跳过" forState:0];
    [skipBtn setTitleColor:[UIColor blackColor] forState:0];
    [skipBtn setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [skipBtn addTarget:self action:@selector(SkipBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:skipBtn];
    
    return headView;
}
//选中按钮
-(void)SelectBtnAction:(UIButton *)sender {
    for (UIButton *btn in SelectBtnArr) {
        btn.selected = NO;
    }
    sender.selected = YES;
}
//跳过按钮
-(void)SkipBtnAction:(UIButton *)sender {
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[LoginYunPlaVC class]]) {
            LoginYunPlaVC *LoginVC = (LoginYunPlaVC *)controller;
            [self.navigationController popToViewController:LoginVC animated:YES];
        }
    }
}
//确定按钮
-(void)SureBtnAction:(UIButton *)sender {
//    Platform_Type type = 0;
//    for (int i = 0; i<SelectBtnArr.count; i++) {
//        UIButton *btn = SelectBtnArr[i];
//        if (btn.selected) {
//            switch (i) {
//                case 0:
//                {
//                    type = personalPlatform;
//                    break;
//                }
//                case 1:
//                {
//                    type = EnterprisePlatform;
//                    break;
//                }case 2:
//                {
//                    type = BusinessAssociation;
//                    break;
//                }
//                case 3:
//                {
//                    type = BusinessUnit;
//                    break;
//                }
//                case 4:
//                {
//                    type = PublicService;
//                    break;
//                }
//                    
//                    
//                default:
//                    break;
//            }
//        }
//    }
//    
//    [self pushViewController:[[PersonalPlatform alloc] initWith:type]];
}

#pragma mark -
#pragma mark --tableviewDelegate--
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *indentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = _headView;
    return headView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    UIView *headView = [self tableView:tableView viewForHeaderInSection:section];
    
    return CGRectGetHeight(headView.frame);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
